﻿using mscook.core.domain;
using mscook.core.services;
using mscook.mvc.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace mscook.mvc.Areas.weblogin.Controllers
{
    public class homeController : BaseController
    {
        //
        // GET: /weblogin/Home/
        private ILoginUserService iLoginUserService;
        private IResourceBonusSettingService iResourceBonusSettingService;

        public homeController(ILoginUserService iLoginUserService, IResourceBonusSettingService iResourceBonusSettingService)
            : base(iLoginUserService)
        {
            this.iLoginUserService = iLoginUserService;
            this.iResourceBonusSettingService = iResourceBonusSettingService;
        }
        [UserAuthorizeAttribute(Roles = "admin,editor")]
        public ActionResult Index()
        {
            InitNavBar();
            return View();
        }
        public ActionResult Login()
        {
            return View();
        }

        public void SetBonus(string resourceId, int bonus, PurchasedCategory purchasedCategory)
        {
            ResourceBonusSetting resourceBonusSetting = iResourceBonusSettingService.SelectByResourceId(resourceId);

            if (resourceBonusSetting == null)
            {
                resourceBonusSetting = new ResourceBonusSetting(resourceId, -Math.Abs(bonus), purchasedCategory);
            }
            else
            {
                resourceBonusSetting.Bonus =  Math.Abs(bonus);
            }

            iResourceBonusSettingService.SaveOrUpdate(resourceBonusSetting);
            
        }

    }
}
